package com.sbwebsocket.core.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sbwebsocket.core.service.ClientManager;
import com.sbwebsocket.core.service.MessageQueueAdapter;
import com.sbwebsocket.core.service.OfflineMessageManager;
import com.sbwebsocket.core.ws.WebSocketServer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @Auther: GSJ
 * @Date: 2022/2/10
 * @Description:
 * @version: 1.0
 */
//@EnableWebSocketMessageBroker
public class WebSocketConfig
//        implements WebSocketMessageBrokerConfigurer
{
//    @Override
//    public void registerStompEndpoints(StompEndpointRegistry registry) {
//        registry.addEndpoint("/socket").setAllowedOrigins("http://127.0.0.1:5500").withSockJS();
//    }

//    @Override
//    public void configureMessageBroker(MessageBrokerRegistry registry) {
//        registry.enableSimpleBroker("/topic");
//    }

    @ConditionalOnMissingBean(ServerEndpointExporter.class)
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
    
    @Bean
    @Order(9999)
    public WebSocketServer webSocketServer(ObjectMapper objectMapper, ClientManager clientManager, MessageQueueAdapter messageQueueAdapter, OfflineMessageManager offlineMessageManager){
        return new WebSocketServer(objectMapper,clientManager,messageQueueAdapter,offlineMessageManager);
    }
}